/******************************************************************************
 Copyright (c) 2021-2025 Qualcomm Technologies International, Ltd.
 All Rights Reserved.
 Qualcomm Technologies International, Ltd. Confidential and Proprietary.

******************************************************************************/


#ifndef GATT_BATTERY_SERVER_ACCESS_H_
#define GATT_BATTERY_SERVER_ACCESS_H_

#include "gatt_battery_server.h"

/* Required octets for values sent to Battery Level Descriptor */
#define GATT_BATTERY_LEVEL_OCTET_SIZE sizeof(uint8) * 1
/* Required maximum octets for values sent to Battery Level Status Descriptor */
#define GATT_BATTERY_LEVEL_STATUS_OCTET_SIZE sizeof(uint8) * 7
/* Required octets for values sent to Battery Level Status Power State Descriptor */
#define GATT_BATTERY_LEVEL_STATUS_POWER_STATE_SIZE sizeof(uint8) * 2
/* Required octets for values sent to Battery Level Status Descriptor Identifier Field */
#define GATT_BATTERY_LEVEL_STATUS_IDENTIFIER_OCTET_SIZE sizeof(uint8) * 2
/* Required octets for values sent to Battery Level Status Descriptor  Addtional Status Field */
#define GATT_BATTERY_LEVEL_STATUS_ADDITIONAL_STATUS_OCTET_SIZE sizeof(uint8) * 1
/* Required octets for values sent to Estimated Service Descriptor */
#define GATT_ESTIMATED_SERVICE_DATE_OCTET_SIZE sizeof(uint8) * 3
/* Required octets for values sent to Battery Critical Status Descriptor */
#define GATT_BATTERY_CRITICAL_STATUS_OCTET_SIZE sizeof(uint8) * 1
/* Required octets for values sent to Battery Energy Status Descriptor */
#define GATT_BATTERY_ENERGY_STATUS_OCTET_SIZE sizeof(uint8) * 13
/* Required octets for values sent to Battery Energy Status Descriptor Fields*/
#define GATT_BATTERY_ENERGY_STATUS_FIELDS_OCTET_SIZE sizeof(uint8) * 2
/* Required octets for values sent to Client Configuration Descriptor */
#define GATT_CLIENT_CONFIG_OCTET_SIZE sizeof(uint8) * 2
/* Required octets for values sent to Server Configuration Descriptor */
#define GATT_SERVER_CONFIG_OCTET_SIZE sizeof(uint8) * 2
/* Required octets for values sent to Presentation Descriptor */
#define GATT_PRESENTATION_OCTET_SIZE sizeof(uint8) * 7
/* Required octets for values sent to flags of Descriptor */
#define GATT_BATTERY_FLAGS_SIZE sizeof(uint8) * 1

#ifdef EXCLUDE_GATT_BATTERY_SERVICE_V1P1

/***************************************************************************
NAME
    sendBatteryConfigAccessRsp

DESCRIPTION
    Send battery config access response to the GATT library as stated by BasPrim for BAS v1P0.
*/
void sendBatteryConfigAccessRsp(const GBASS* battery_server, uint32 cid, uint16 client_config);

/***************************************************************************
NAME
    sendBatteryPresentationAccessRsp

DESCRIPTION
    Send battery presentation access response to the GATT library as stated by BasPrim for BAS v1P0.
*/
void sendBatteryPresentationAccessRsp(const GBASS* battery_server, uint32 cid, uint8 name_space, uint16 description);

#else
typedef uint16 BasPrim;

/***************************************************************************
NAME
    sendBatteryConfigAccessRsp

DESCRIPTION
    Send battery config access response to the GATT library as stated by BasPrim for BAS v1P1.
*/
void sendBatteryConfigAccessRsp(const GBASS* batteryServer, uint32 cid, BasPrim primType, uint16 clientConfig);

/***************************************************************************
NAME
    sendBatteryPresentationAccessRsp

DESCRIPTION
    Send battery presentation access response to the GATT library as stated by BasPrim for BAS v1P1.
*/
void sendBatteryPresentationAccessRsp(const GBASS* batteryServer, uint32 cid, BasPrim primType, uint8 nameSpace, uint16 description);
#endif /* EXCLUDE_GATT_BATTERY_SERVICE_V1P1 */

/***************************************************************************
NAME
    sendBatteryLevelAccessRsp

DESCRIPTION
    Send battery level access response to the GATT library.
*/
void sendBatteryLevelAccessRsp(const GBASS* battery_server, uint32 cid, uint8 battery_level, uint16 result);

/***************************************************************************
NAME
    handleBatteryServerWriteAccess

DESCRIPTION
    Handles the CsrBtGattDbAccessWriteInd message that was sent to the battery library.
*/
void handleBatteryServerWriteAccess(GBASS* battery_server, const CsrBtGattDbAccessWriteInd* access_ind);

/***************************************************************************
NAME
    handleBatteryServerReadAccess

DESCRIPTION
    Handles the CsrBtGattDbAccessReadInd message that was sent to the battery library.
*/
void handleBatteryServerReadAccess(GBASS* battery_server, const CsrBtGattDbAccessReadInd* access_ind);

/***************************************************************************
NAME
    batteryReadAccess

DESCRIPTION
    Send battery read access msg to application for the respective prim as stated by handle value.
*/
void batteryReadAccess(GBASS* battery_server, const CsrBtGattDbAccessReadInd* access_ind);

#ifndef EXCLUDE_GATT_BATTERY_SERVICE_V1P1 

/***************************************************************************
NAME
    sendBatteryTimeStatusAccessRsp

DESCRIPTION
    Send battery time status access response to the GATT library.
*/
void sendBatteryTimeStatusAccessRsp(const GBASS* batteryServer, uint32 cid, GattBatteryTimeStatus currentBatteryTimeStatus, uint16 result);

/***************************************************************************
NAME
    sendBatteryHealthStatusAccessRsp

DESCRIPTION
    Send battery health status access response to the GATT library.
*/
void sendBatteryHealthStatusAccessRsp(const GBASS* batteryServer, uint32 cid, GattBatteryHealthStatus batteryHealthStatus, uint16 result);

/***************************************************************************
NAME
    sendBatteryHealthInformationAccessRsp

DESCRIPTION
    Send battery health information access response to the GATT library.
*/
void sendBatteryHealthInformationAccessRsp(const GBASS* batteryServer, uint32 cid, GattBatteryHealthInformation batteryHealthInformation, uint16 result);

/***************************************************************************
NAME
    sendBatteryInformationAccessRsp

DESCRIPTION
    Send battery information access response to the GATT library.
*/
void sendBatteryInformationAccessRsp(const GBASS* batteryServer, uint32 cid, GattBatteryInformation batteryInformation, uint16 result);

/***************************************************************************
NAME
    sendManufacturerNameStringAccessRsp

DESCRIPTION
    Send manufacturer name string access response to the GATT library.
*/
void sendManufacturerNameStringAccessRsp(const GBASS* batteryServer, uint32 cid, uint8* manufacturerNameString, uint16 result);

/***************************************************************************
NAME
    sendModelNumberStringAccessRsp

DESCRIPTION
    Send model number string access response to the GATT library.
*/
void sendModelNumberStringAccessRsp(const GBASS* batteryServer, uint32 cid, uint8* modelNumberString, uint16 result);

/***************************************************************************
NAME
handleBatteryServerSendCfmEvent

DESCRIPTION
Handles the CsrBtGattEventSendCfm message that was sent to the battery library.
*/
void handleBatteryServerSendCfmEvent(GBASS * batteryServer, const CsrBtGattEventSendCfm* accessInd);

/***************************************************************************
NAME
    sendBatterylevelStatusAccessRsp
    
DESCRIPTION
    Send battery level status access response to the GATT library.
*/
void sendBatteryLevelStatusAccessRsp(const GBASS* batteryServer, uint32 cid, GattBatteryLevelStatus batteryLevelStatus, uint16 result);

/***************************************************************************
NAME
    sendBatteryEastimatedServiceDateAccessRsp

DESCRIPTION
    Send battery estimated service date access response to the GATT library.
*/
void sendBatteryEstimatedServiceDateAccessRsp(const GBASS* batteryServer, uint32 cid, uint32 estimatedServiceDate, uint16 result);

/***************************************************************************
NAME
    sendBatteryCriticalStatusAccessRsp

DESCRIPTION
    Send battery critical status access response to the GATT library.
*/
void sendBatteryCriticalStatusAccessRsp(const GBASS* batteryServer, uint32 cid, uint8 batteryCriticalStatus, uint16 result);

/***************************************************************************
NAME
    sendBatteryEnergyStatusAccessRsp

DESCRIPTION
    Send battery energy status access response to the GATT library.
*/
void sendBatteryEnergyStatusAccessRsp(const GBASS* batteryServer, uint32 cid, GattBatteryEnergyStatus batteryEnergyStatus, uint16 result);

/***************************************************************************
NAME
    sendBatterySerialNumberAccessRsp

DESCRIPTION
    Send battery critical status access response to the GATT library.
*/
void sendBatterySerialNumberAccessRsp(const GBASS* batteryServer, uint32 cid, uint8* serailNumber, uint16 size, uint16 result);
#endif

#endif
